package com.beiing.tianshuai.tianshuai.widget;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.beiing.tianshuai.tianshuai.R;


/**
 * Created by Jinni on 2017/4/11.
 */

public class FooterView extends LinearLayout {
    private Context mContext;

    public static final int HIDE = 0;
    public static final int MORE = 1;
    public static final int LOADING = 2;
    public static final int BAD_NETWORK = 3;
    public static final int NO_MORE = 4;

    private ProgressBar progressBar;
    private TextView textView;

    private int curStatus;

    public FooterView(Context context, AttributeSet attrs) {
        super(context, attrs);
        mContext = context;
        init();
    }

    public FooterView(Context context) {
        super(context);
        mContext = context;
        init();
    }

    private void init() {
        LayoutInflater.from(mContext).inflate(R.layout.listview_footer, this, true);
        progressBar = (ProgressBar) findViewById(R.id.footer_loading);
        textView = (TextView) findViewById(R.id.footer_text);
        setStatus(HIDE);
    }

    public void setStatus(int status) {
        curStatus = status;
        switch (status) {
            case HIDE:
                setVisibility(View.GONE);
                break;
            case MORE:
                progressBar.setVisibility(View.GONE);
                textView.setVisibility(View.VISIBLE);
                textView.setText("点击加载更多");
                this.setVisibility(View.VISIBLE);
                break;
            case NO_MORE:
                progressBar.setVisibility(View.GONE);
                textView.setVisibility(View.VISIBLE);
                textView.setText(R.string.footer_end);
                this.setVisibility(View.VISIBLE);
                break;
            case LOADING:
                progressBar.setVisibility(View.VISIBLE);
                textView.setVisibility(View.VISIBLE);
                textView.setText("正在加载...");
                this.setVisibility(View.VISIBLE);
                break;
            case BAD_NETWORK:
                progressBar.setVisibility(View.GONE);
                textView.setVisibility(View.VISIBLE);
                textView.setText("网络连接有问题");
                this.setVisibility(View.VISIBLE);
                break;
        }
    }

    public int getStatus() {
        return curStatus;
    }

}